import logging

from fastapi import APIRouter, Depends

from like.schema_base import PageInationResult
from like.http_base import unified_resp
from .schemas import (
    MedicalDipGeneralDiseaseTypesListIn, MedicalDipGeneralDiseaseTypesExportIn, MedicalDipGeneralDiseaseTypesDetailIn, MedicalDipGeneralDiseaseTypesAddIn, 
    MedicalDipGeneralDiseaseTypesEditIn, MedicalDipGeneralDiseaseTypesDelIn, MedicalDipGeneralDiseaseTypesOut)
from .service import IMedicalDipGeneralDiseaseTypesService, MedicalDipGeneralDiseaseTypesService

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/types')


@router.get('/list', response_model=PageInationResult[MedicalDipGeneralDiseaseTypesOut])
@unified_resp
async def types_list(
        list_in: MedicalDipGeneralDiseaseTypesListIn = Depends(),
        medical_dip_general_disease_types_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    """存储 DIP 综合病种相关信息的列表"""
    result = await medical_dip_general_disease_types_service.list(list_in)
    # result.file_name = "存储 DIP 综合病种相关信息的"
    return result

@router.get('/export', response_model=bytes)
@unified_resp
async def types_export(export_in: MedicalDipGeneralDiseaseTypesExportIn = Depends(), MedicalDipGeneralDiseaseTypes_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    return await MedicalDipGeneralDiseaseTypes_service.export_excel(export_in)


@router.get('/detail')
@unified_resp
async def types_detail(
        detail_in: MedicalDipGeneralDiseaseTypesDetailIn = Depends(),
        medical_dip_general_disease_types_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    """存储 DIP 综合病种相关信息的详情"""
    return await medical_dip_general_disease_types_service.detail(detail_in.id)


@router.post('/add')
@unified_resp
async def types_add(
        add_in: MedicalDipGeneralDiseaseTypesAddIn,
        medical_dip_general_disease_types_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    """存储 DIP 综合病种相关信息的新增"""
    return await medical_dip_general_disease_types_service.add(add_in)


@router.post('/edit')
@unified_resp
async def types_edit(
        edit_in: MedicalDipGeneralDiseaseTypesEditIn,
        medical_dip_general_disease_types_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    """存储 DIP 综合病种相关信息的编辑"""
    return await medical_dip_general_disease_types_service.edit(edit_in)


@router.post('/del')
@unified_resp
async def types_del(
        del_in: MedicalDipGeneralDiseaseTypesDelIn,
        medical_dip_general_disease_types_service: IMedicalDipGeneralDiseaseTypesService = Depends(MedicalDipGeneralDiseaseTypesService.instance)):
    """存储 DIP 综合病种相关信息的删除"""
    return await medical_dip_general_disease_types_service.delete(del_in.id)
